package com.action;

import com.dao.TAdminDAO;
import com.model.TAdmin;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;

import java.util.List;
import java.util.Map;

public class AdminAction extends ActionSupport {
    private int userId;
    private String userName;
    private String userPw;

    private String message;
    private String path;

    private int index = 1;

    private TAdminDAO adminDAO;


    public String adminAdd() {
        TAdmin admin = new TAdmin();
        admin.setUserName(userName);
        admin.setUserPw(userPw);
        adminDAO.save(admin);
        this.setMessage("操作成功");
        this.setPath("adminManage.action");
        return "succeed";
    }


    public String adminManage() {
        List adminList = adminDAO.findAll();
        Map request = (Map) ServletActionContext.getContext().get("request");
        request.put("adminList", adminList);
        return ActionSupport.SUCCESS;
    }


    public String adminDel() {
        adminDAO.delete(adminDAO.findById(userId));
        this.setMessage("操作成功");
        this.setPath("adminManage.action");
        return "succeed";
    }


    public TAdminDAO getAdminDAO() {
        return adminDAO;
    }

    public void setAdminDAO(TAdminDAO adminDAO) {
        this.adminDAO = adminDAO;
    }

    public String getMessage() {
        return message;
    }

    public int getIndex() {
        return index;
    }


    public void setIndex(int index) {
        this.index = index;
    }


    public void setMessage(String message) {
        this.message = message;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserPw() {
        return userPw;
    }

    public void setUserPw(String userPw) {
        this.userPw = userPw;
    }

}
